//
//  OtherSettingsVC.m
//  wanzhaoIM
//
//  Created by liuyuantao on 15/5/6.
//  Copyright (c) 2015年 liuyuantao. All rights reserved.
//

#import "OtherSettingsVC.h"
#import "MicroDef.h"
#import "SettingMidTextCell.h"
#import "JKAlertDialog.h"
#import "CMessageMgr.h"
#import "CMessageDraftMgr.h"

#define KSECTIONHEIGHT 20.0f
@interface OtherSettingsVC ()<UITableViewDelegate, UITableViewDataSource>
{
    UITableView *_tableView;
}
@end

@implementation OtherSettingsVC

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.navigationController setNavigationBarHidden:NO];
    [self.navigationItem setHidesBackButton:YES];
    [self.navigationItem setNewTitleCenter:@"其他设置"];
    
    _tableView = [[UITableView alloc] init];
    _tableView.frame = CGRectMake(0, 0, HARDWARE_SCREEN_WIDTH, HARDWARE_SCREEN_HEIGHT - 64.0f);
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_tableView];
    _tableView.backgroundColor = [UIColor clearColor];
    
    
    self.view.backgroundColor = RGBCOLOR(0xf3, 0xf3, 0xf3);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    NSInteger rows = 0;
    
    switch (section) {
        case 0:
            rows = 2;
            break;
        default:
            rows = 0;
            break;
    }
    return rows;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView              // Default is 1 if not implemented
{
    return 1;
}
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"SettingMidTextCell";
//    DLog(@"section:%d, rows:%d", indexPath.section, indexPath.row);
    UITableViewCell *cell = nil;
    SettingMidTextCell *logoutCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (logoutCell == nil) {
        logoutCell = [[[NSBundle mainBundle] loadNibNamed:@"SettingMidTextCell" owner:self options:nil] objectAtIndex:0];
    }
    
    [logoutCell.titleLabel setText:[self titleName:indexPath]];
    logoutCell.accessoryType = UITableViewCellAccessoryNone;
    if(indexPath.section == 0 && (indexPath.row == 0 ))
    {
        [logoutCell.seperatorLine setHidden:NO];
    }
    else
    {
        [logoutCell.seperatorLine setHidden:YES];
    }
    
    
    
    cell = logoutCell;
    
    return cell;
}

-(NSString *)titleName:(NSIndexPath *)indexPath
{
    NSString *title = nil;
    
    switch (indexPath.section) {
        case 0:
        {
            switch (indexPath.row) {
                case 0:
                    title = @"清空消息列表";
                    break;
                case 1:
                    title = @"清空所有聊天记录";
                    break;
                default:
                    break;
            }
        }
            break;
        default:
            break;
    }
    return title;
}




#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    CGFloat height = 0;
    switch (section) {
        case 0:
            height = 0;
            break;
        default:
            break;
    }
    return height;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    CGFloat height = 0;
    switch (section) {
        case 0:
            height = KSECTIONHEIGHT;
            break;
        default:
            break;
    }
    return height;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section   // custom view for header. will be adjusted to default or specified header height
{
    UIView *headerView = nil;
    //    if(section == 0)
    //    {
    //        return headerView;
    //    }
    //    headerView = [[UIView alloc] init];
    //    headerView.frame = CGRectMake(0, 0, tableView.frame.size.width, KSECTIONHEIGHT);
    //    headerView.backgroundColor = RGBCOLOR(0xf3, 0xf3, 0xf3);
    //    UIView *beginLine = [[UIView alloc] init];
    //    beginLine.frame = CGRectMake(0, 0, tableView.frame.size.width, 0.5);
    //    [beginLine setBackgroundColor:KSEPERATORLINECOLOR];
    //    [headerView addSubview:beginLine];
    //
    //    UIView *endLine = [[UIView alloc] init];
    //    endLine.frame = CGRectMake(0, KSECTIONHEIGHT-0.5, tableView.frame.size.width, 0.5);
    //    [endLine setBackgroundColor:KSEPERATORLINECOLOR];
    //    [headerView addSubview:endLine];
    
    return headerView;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section   // custom view for footer. will be adjusted to default or specified footer height
{
    UIView *headerView = nil;
    if(section != 0)
    {
        return headerView;
    }
    headerView = [[UIView alloc] init];
    headerView.frame = CGRectMake(0, 0, tableView.frame.size.width, 3);
    headerView.backgroundColor = RGBCOLOR(0xf3, 0xf3, 0xf3);
    UIView *beginLine = [[UIView alloc] init];
    beginLine.frame = CGRectMake(0, 0, tableView.frame.size.width, 0.5);
    [beginLine setBackgroundColor:KSEPERATORLINECOLOR];
    [headerView addSubview:beginLine];
    
    
    
    return headerView;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat height = 50.0f;
    
    if(indexPath.row == 0 && indexPath.section == 0)
    {
        height = 50.0f;
    }
    return height;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.section) {
        case 0:
        {
            switch (indexPath.row) {
                case 0:
                {
                    JKAlertDialog *alert = [[JKAlertDialog alloc]initWithTitle:nil message:@"是否清空所有消息列表信息?"];
                    [alert addButton:Button_OK withTitle:@"是" handler:^(JKAlertDialogItem *item) {
                        [[[CMessageMgr alloc] init] updateMessageWithIsShowInMessageList:NO];
                        [[[CMessageDraftMgr alloc] init] delAllMessageDraft];
                        [[NSNotificationCenter defaultCenter] postNotificationName:@"TabBadgeChangeValue" object:nil];
                    }];
                    [alert addButton:Button_OK withTitle:@"否" handler:^(JKAlertDialogItem *item) {
                        
                    }];
                    [alert show];
                }
                    break;
                case 1:
                {
                    JKAlertDialog *alert = [[JKAlertDialog alloc]initWithTitle:nil message:@"是否清空与所有人的聊天记录?"];
                    [alert addButton:Button_OK withTitle:@"是" handler:^(JKAlertDialogItem *item) {
                        [[[CMessageMgr alloc] init] delAllMessages];
                        [[[CMessageDraftMgr alloc] init] delAllMessageDraft];
                        [[NSNotificationCenter defaultCenter] postNotificationName:@"TabBadgeChangeValue" object:nil];
                    }];
                    [alert addButton:Button_OK withTitle:@"否" handler:^(JKAlertDialogItem *item) {
                    }];
                    [alert show];
                }
                    break;
                default:
                    break;
            }
        }
            break;
        default:
            break;
    }
    
    
}


-(void)showAboutVC
{
    
}

-(void)showSettingVC
{
    
}

@end
